Remove the handling of TypeError inside gather. It is not thrown by int()
authoremellor@leeni.uk.xensource.com <emellor@leeni.uk.xensource.com>
Tue, 15 Nov 2005 17:47:39 +0000 (18:47 +0100)
committeremellor@leeni.uk.xensource.com <emellor@leeni.uk.xensource.com>
Tue, 15 Nov 2005 17:47:39 +0000 (18:47 +0100)
when given a non-convertible value, as claimed by the comment, as the exception
ValueError is thrown in that situation.  TypeError is only thrown on int(None),
which cannot actually take place in this code, because of the explicit check
for None.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
tools/python/xen/xend/xenstore/xstransact.py

index ac06c2b1b8ab47119cbb41995bc5787599ca097e..dcdad54a226c588d74995de66ecd65ae9cc87a03 100644 (file)
@@ -177,18 +177,15 @@ class xstransact:
                 (key, fn, defval) = tup
 
             val = self._read(key)
-            # If fn is str, then this will successfully convert None to
-            # 'None'.  If it is int, then it will throw TypeError on None, or
-            # on any other non-integer value.  We have to, therefore, both
-            # check explicitly for None, and catch TypeError.  Either failure
-            # will result in defval being used instead.
+            # If fn is str, then this will successfully convert None to 'None'
+            # (which we don't want).  If it is int or float, then it will
+            # throw ValueError on any non-convertible value.  We check
+            # explicitly for None, using defval instead, but allow ValueError
+            # to propagate.
             if val is None:
                 val = defval
             else:
-                try:
-                    val = fn(val)
-                except TypeError:
-                    val = defval
+                val = fn(val)
             ret.append(val)
         if len(ret) == 1:
             return ret[0]